@extends('admin.layout')
@section('title','用户列表')
@section('body')

    <div id="search" style="height:63px;">
        <blockquote class="layui-elem-quote" style="font-size: 14px">
            <form action="" method="post" class="layui-form">
                <div class="layui-form-item">
                    <div  class="layui-inline">
                        <label class="layui-form-label">搜索</label>
                        <div class="layui-input-inline">
                            <input type="tel" id="" name="name"  lay-verify="required" placeholder="请输入类名" autocomplete="off" class="layui-input ">
                            <input type="hidden" name="type" value="search">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <input  type="submit" class="layui-btn layui-btn-small" value="搜索">
                        <a href="javascript:history.back()" class="layui-btn layui-btn-small" >返回</a>
                        <input type="button" onclick="ins()" class="layui-btn layui-btn-small" value="添加">
                    </div>
                </div>

            </form>
        </blockquote>
    </div>
    <table class="layui-table " lay-even lay-skin="line">
        <colgroup>

        </colgroup>
        <thead>
        <tr>

            <th>{{$pa_id==0?'一级':'二级'}}分类名</th>
            <th>图片</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        @foreach($classify as $value)

                <tr onclick="{{$value->pa_id==0?'':'return false'}} location.href='{{url('classify/lists')}}?classify_id={{$value->classify_id}}'">
                    <td>{{$value->name}}</td>
                    <td><img style="width: 100px;height: 100px" src="{{url($value->my_img?$value->my_img->pic_path:"")}}"></td>
                    <td>
                        <button onclick="edit('{{$value->name}}','{{$value->classify_id}}','{{$value->sort}}');" class="layui-btn layui-btn-normal layui-btn-mini">修改</button>
                        <button onclick="del('{{$value->classify_id}}');return false;" class="layui-btn layui-btn-mini">删除</button>
                    </td>
                </tr>

        @endforeach
        </tbody>
    </table>
{{$classify->links()}}

@endsection
@section('js')

    <script>
        @if(Session::has('message'))
             layer.msg("{{Session::get("message")}}");
                {{Session::forget('message')}}
        @endif
        function ins() {
            layer.open({
                title:"添加分类",
                content:'<form id="ins" action="{{url('classify/create')}}" method="post" enctype="multipart/form-data"><input type="text" class="layui-input" name="name" placeholder="分类名" /><br/>图片<input name="img"  type="file"/><br/>排序<input type="integer"  class="layui-input" name="sort" value="0"><input type="hidden"  name="pa_id" value="{{$pa_id}}">{{csrf_field()}}</form>',
                yes:function () {
                    $("#ins").submit();
                }
            });
        }
        function edit(name,id,sort) {
            layer.open({
                title:"修改分类",
                content:'<form id="edit" method="post"  action="{{url('classify/edit')}}" enctype="multipart/form-data"  ><input type="text" class="layui-input" name="name" value="'+name+'" /><input type="hidden" name="classify_id" value="'+id+'"><br/>图片<input name="img"  type="file"/><br/>排序<input type="integer"  class="layui-input" name="sort" value="'+sort+'">{{csrf_field()}}</form>',
                yes:function () {
                    $("#edit").submit();

                }
            });
            event.stopPropagation();
        }

        function del(id) {
            layer.open({
                title:"提示",
                content:'确定删除吗？子分类及商品也将删除！<form id="del" method="post"  action="{{url('classify/destory')}}"><input type="hidden" name="classify_id" value="'+id+'">{{csrf_field()}}</form>',
                yes:function () {
                    $("#del").submit();
                }
            });
            event.stopPropagation();
        }

    </script>

@endsection

